﻿
using System.Text;
using System.Web.Script.Serialization;
namespace HuaCheng.CommonClass
{
    public class JsonHelper
    {
        /// <summary>
        /// 把json字符串转换成对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="data"></param>
        /// <returns></returns>
        public static T Deserialize<T>(string data)
        {
            JavaScriptSerializer json = new JavaScriptSerializer();
            return json.Deserialize<T>(data);
        }
        /// <summary>
        /// 把对象转换成json串
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public static string Serialize(object o)
        {
            StringBuilder sb = new StringBuilder();
            JavaScriptSerializer json = new JavaScriptSerializer();
            json.Serialize(o, sb);
            return sb.ToString();
        }
    }
}
